package com.example.mybusschedule.di

import android.content.Context
import com.example.mybusschedule.data.BusScheduleDao
import com.example.mybusschedule.data.BusScheduleDatabase
import com.example.mybusschedule.data.BusScheduleRepository
import com.example.mybusschedule.data.OfflineBusScheduleRepository
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class BusScheduleModule {
    @Singleton
    @Binds
    abstract fun bindBusScheduleRepository(
        busScheduleRepository: OfflineBusScheduleRepository
    ): BusScheduleRepository
}

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {
    @Singleton
    @Provides
    fun provideBusScheduleDatabase(
        @ApplicationContext context: Context
    ): BusScheduleDatabase = BusScheduleDatabase.getDatabase(context)

    @Provides
    fun provideBusScheduleDao(
        busScheduleDatabase: BusScheduleDatabase
    ): BusScheduleDao = busScheduleDatabase.busScheduleDao()
}